package com.zhaoyh.websocket;

import com.zhaoyh.framework.code.util.LogUtil;

import javax.websocket.*;
/**
 * @author 祥霸
 * @date 2019/4/15
 */
@ClientEndpoint
public class Client {
    @OnOpen
    public void onOpen(Session session) {
        LogUtil.log.info("---------- 链接成功 ---------------");
        System.out.println("Connected to endpoint: " + session.getBasicRemote());
    }

    @OnMessage
    public void onMessage(String message) {
        LogUtil.log.info("------------ onMessage ------------");
        System.out.println(message);
    }

    @OnError
    public void onError(Throwable t) {
        LogUtil.log.info("------------ 链接失败 -------------");
        t.printStackTrace();
    }

    @OnClose
    public void onClose(Session session) {
        LogUtil.log.info("----------- 断开连接 --------------");
        System.out.println("Connected to endpoint: " + session.getBasicRemote());
    }
}
